/************************************************************************
                                                                     
   Xceed Ultimate ListBox for Silverlight                                                                                                                                            
   Copyright (C) 2010 Xceed Software Inc.    
                                                                     
   This program is provided to you under the terms of the GNU General Public  
   License version 2 as published by the Free Software Foundation. 
        
   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY, without even the implied warranty of 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License along 
   with this program, if not, write to the Free Software Foundation, Inc., 
   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

   This program can be provided to you by Xceed Software Inc. under a
   proprietary commercial license agreement for use in non-Open Source
   projects. Visit Xceed.com to find the commercial edition of 
   Xceed Ultimate ListBox for Silverlight.                                    
                                                                      
 **********************************************************************/

using System;

namespace Xceed.Silverlight.Data
{
  public abstract class AsyncDataSourceProvider : DataSourceProvider, IAsyncDataSourceProvider
  {
    #region Constructor

    protected AsyncDataSourceProvider()
      : base()
    {
    }

    #endregion

    #region CanFilter Property

    public override bool CanFilter
    {
      get
      {
        return true;
      }
    }

    #endregion

    #region CanSkip Property

    public override bool CanSkip
    {
      get
      {
        return true;
      }
    }

    #endregion

    #region CanSort Property

    internal override sealed bool CanSort
    {
      get
      {
        return true;
      }
    }

    #endregion

    #region QueryRequestInterval Property

    public TimeSpan QueryRequestInterval
    {
      get
      {
        return m_queryRequestInterval;
      }
      set
      {
        m_queryRequestInterval = value;
      }
    }

    private TimeSpan m_queryRequestInterval = TimeSpan.Zero;

    #endregion

    #region BufferConfiguration Property

    public BufferConfiguration BufferConfiguration
    {
      get
      {
        return m_bufferConfiguration;
      }
      set
      {
        if( value != m_bufferConfiguration )
        {
          m_bufferConfiguration = value;
        }
      }
    }

    private BufferConfiguration m_bufferConfiguration = new DynamicBufferConfiguration();

    #endregion

    #region IsAsynchronous Property

    internal sealed override bool IsAsynchronous
    {
      get
      {
        return true;
      }
    }

    #endregion

    #region IsCachingAllowed Property

    internal override bool IsCachingAllowed
    {
      get
      {
        return true;
      }
    }

    #endregion

    #region IsBufferingAllowed Property

    internal override bool IsBufferingAllowed
    {
      get
      {
        return true;
      }
    }

    #endregion

    protected abstract IAsyncResult BeginExecuteCountQuery(
      CountQueryParameters queryParameters,
      AsyncCallback callback,
      object state );

    protected abstract CountQueryResult EndExecuteCountQuery( IAsyncResult asyncResult );

    protected abstract IAsyncResult BeginExecuteDataQuery(
      DataQueryParameters queryParameters,
      AsyncCallback callback,
      object state );

    protected abstract DataQueryResult EndExecuteDataQuery( IAsyncResult asyncResult );

    protected abstract IAsyncResult BeginExecuteGroupCountQuery(
     GroupCountQueryParameters queryParameters,
     AsyncCallback callback,
     object state );

    protected abstract GroupCountQueryResult EndExecuteGroupCountQuery( IAsyncResult asyncResult );

    protected abstract IAsyncResult BeginExecuteStatQuery(
     StatQueryParameters queryParameters,
     AsyncCallback callback,
     object state );

    protected abstract StatQueryResult EndExecuteStatQuery( IAsyncResult asyncResult );

    internal override IAsyncResult BeginExecuteCountQueryCore(
      CountQueryParameters queryParameters,
      AsyncCallback callback,
      object state )
    {
      return this.BeginExecuteCountQuery( queryParameters, callback, state );
    }

    internal override CountQueryResult EndExecuteCountQueryCore( IAsyncResult asyncResult )
    {
      return this.EndExecuteCountQuery( asyncResult );
    }

    internal override IAsyncResult BeginExecuteDataQueryCore(
      DataQueryParameters queryParameters,
      AsyncCallback callback,
      object state )
    {
      return this.BeginExecuteDataQuery( queryParameters, callback, state );
    }

    internal override DataQueryResult EndExecuteDataQueryCore( IAsyncResult asyncResult )
    {
      return this.EndExecuteDataQuery( asyncResult );
    }

    internal override IAsyncResult BeginExecuteGroupCountQueryCore(
      GroupCountQueryParameters queryParameters,
      AsyncCallback callback,
      object state )
    {
      return this.BeginExecuteGroupCountQuery( queryParameters, callback, state );
    }

    internal override GroupCountQueryResult EndExecuteGroupCountQueryCore( IAsyncResult asyncResult )
    {
      return this.EndExecuteGroupCountQuery( asyncResult );
    }

    internal override IAsyncResult BeginExecuteStatQueryCore(
      StatQueryParameters queryParameters,
      AsyncCallback callback,
      object state )
    {
      return this.BeginExecuteStatQuery( queryParameters, callback, state );
    }

    internal override StatQueryResult EndExecuteStatQueryCore( IAsyncResult asyncResult )
    {
      return this.EndExecuteStatQuery( asyncResult );
    }
  }
}
